﻿Imports System.IO
Imports System.Xml.Serialization

Public Class XMLHelper


    Public Shared Sub SerializeObject(ByVal item As Object, ByVal Path As String)

        'Serialize object to a text file.
        Dim objStreamWriter As New StreamWriter(Path)
        Dim x As New XmlSerializer(item.GetType)
        x.Serialize(objStreamWriter, item)
        objStreamWriter.Close()

    End Sub

    Public Shared Function DeserializeObject(ByVal item As Object, ByVal Path As String) As Object

        'Deserialize text file to a new object.
        'Dim myAppSettings As New AppSettings

        '***************************************************
        'Need to add checking to make sure file exists
        '***************************************************
        Dim fi As New FileInfo(Path)

        If fi.Exists Then
            Dim objStreamReader As New StreamReader(Path)

            Dim x As New XmlSerializer(item.GetType)
            item = x.Deserialize(objStreamReader)
            objStreamReader.Close()
        End If

        Return item

    End Function


End Class
